<template>
  <div>
    <el-form
      :model="ruleForm"
      ref="ruleForm"
      label-width="100px"
      class="demo-ruleForm"
      :rules="rules"
    >
      <el-form-item label="登录名" prop="name">
        <el-input v-model="ruleForm.name" style="width: 250px"></el-input>
      </el-form-item>
      <el-form-item label="昵称" prop="region">
        <el-input v-model="ruleForm.region" style="width: 250px"></el-input>
      </el-form-item>

      <el-form-item>
        <el-button type="danger" @click="nicheng()" >确认修改</el-button>
      </el-form-item>
    </el-form>

    <hr />
    <div class="mima">
      <el-form
        :model="ruleForm"
        ref="ruleForm"
        label-width="100px"
        class="demo-ruleForm"
        :rules="rules"
      >
        <el-form-item label="原密码" prop="password">
          <el-input v-model="ruleForm.password" style="width: 250px"></el-input>
        </el-form-item>
        <el-form-item label="新密码" prop="newpassword"
       
        >
          <el-input
            v-model="ruleForm.newpassword"
            style="width: 250px"
            type="password"
          ></el-input>
        </el-form-item>

        <el-form-item>
          <el-button type="danger" @click="mima()">确认修改</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
 import md5 from 'md5'
export default {
  data() {
    return {
      pwd:"123456",
      tableData:[],
      ruleForm: {
        name: "",
        region: "",
        password: "",
        newpassword: "",
        
      },
      rules: {
        name: [
          { required: true, message: "请输入密码", trigger: "blur" },
          { min: 3, max: 15, message: "长度在 3 到 5 个字符", trigger: "blur" },
        ],
        region: [
          { required: true, message: "请输入昵称", trigger: "blur" },
          { min: 3, max: 15, message: "长度在 3 到 5 个字符", trigger: "blur" },
        ],
        password: [
          { required: true, message: "请输入原密码", trigger: "blur" },
          { min: 5, max: 10, message: "长度在 5 到 10 个字符", trigger: "blur" },
        ],
        newpassword: [
          { required: true, message: "请输入新密码", trigger: "blur" },
          { min: 5, max: 10, message: "长度在 5 到 10 个字符", trigger: "blur" },
        ],
      },
    };
  },
  mounted(){
    this.getfun()
  },
  methods:{
   async nicheng(){//昵称的修改
      let result=await this.$http.put("/adminUser/name",{
        loginUserName: this.ruleForm.name,
        nickName: this.ruleForm.region
      })
      this.$notify({
          title: '成功',
          message: '修改昵称成功',
          type: 'success'
        });
    },
    async getfun() {//获取

      let result = await this.$http.get("/adminUser/profile", { 
      });
      console.log(result);
      this.ruleForm.name=result.data.loginUserName
      this.ruleForm.region=result.data.nickName
      // this.ruleForm.password=result.data.loginPassword
      console.log(this.$md5(this.value));
      // this.totalCount = result.data.totalCount;
      // this.tableData = result.data.list;
      // console.log(this.tableData);
      // this.carouselUrl = result.data.list.carouselUrl;
    },
    mima(){
     
      if (this.ruleForm.password==this.pwd) {
        this.mimaxg()
       
      }else{
        this.$notify.error({
          title: '错误',
          message: '原密码错误'
        });
      }
    },
    async mimaxg(){//密码的修改
      let result= await this.$http.put("/adminUser/password",{
        newPassword:md5(this.ruleForm.newpassword) ,
        originalPassword:md5(this.ruleForm.password) 
      })
      this.$notify({
          title: '成功',
          message: '修改密码成功',
          type: 'success'
        });
        this.pwd=this.ruleForm.newpassword
        console.log(this.pwd);
    },
     

  },
 
};
</script>

<style lang="less" scoped>
.mima {
  margin-top: 50px;
}
</style>

